/**
 * Created by IntelliJ IDEA.
 * User: Taras_Brzezinsky
 * Date: 8/19/11
 * Time: 5:53 PM
 * To change this template use File | Settings | File Templates.
 */

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.IOException;
import java.util.Arrays;
import java.util.StringTokenizer;

public class TaskC extends Thread {
    public TaskC() {
        this.input = new BufferedReader(new InputStreamReader(System.in));
        this.output = new PrintWriter(System.out);
        this.setPriority(Thread.MAX_PRIORITY);
    }

    private int go(int rest, int ind) {
        if (rest <= 0 || ind >= a.length) {
            return 0;
        }
        if (cache[rest][ind + 1] != -1) {
            return cache[rest][ind + 1];
        }
        if (ind == -1) {
            int result = Integer.MIN_VALUE;
            for (int count = 0; count <= (rest / C); ++count) {
                result = Math.max(D * count + go(rest - count * C, ind + 1), result);
            }
            cache[rest][ind + 1] = result;
            return result;
        } else {
            int result = Integer.MIN_VALUE;
            for (int count = 0; count <= Math.min(rest / c[ind], a[ind] / b[ind]); ++count) {
                result = Math.max(result, count * d[ind] + go(rest - count * c[ind], ind + 1));
            }
            cache[rest][ind + 1] = result;
            return result;
        }
    }

    private void solve() throws Throwable {
        int n = nextInt();
        int m = nextInt();
        C = nextInt();
        D = nextInt();
        a = new int[m];
        b = new int[m];
        c = new int[m];
        d = new int[m];
        cache = new int[n + 1][m + 1];
        for (int[] cur : cache) {
            Arrays.fill(cur, -1);
        }
        for (int i = 0; i < m; ++i) {
            a[i] = nextInt();
            b[i] = nextInt();
            c[i] = nextInt();
            d[i] = nextInt();
        }
        long time = System.currentTimeMillis();
        output.println(go(n, -1));
         System.err.println(.001 * (System.currentTimeMillis() - 1));
    }

    public void run() {
        try {
            solve();

        } catch (Throwable e) {
            System.err.println(e.getMessage());
            e.printStackTrace();
            System.exit(666);
        } finally {
            output.flush();
            output.close();
        }
    }

    public static void main(String[] args) {
        new TaskC().start();
    }

    private int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    private long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    private double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    private String nextToken() throws IOException {
        while (tokens == null || !tokens.hasMoreTokens()) {
            tokens = new StringTokenizer(input.readLine());
        }
        return tokens.nextToken();
    }

    private int[][] cache;
    private int[] a;
    private int[] c;
    private int[] b;
    private int[] d;
    private int C, D;
    private BufferedReader input;
    private PrintWriter output;
    private StringTokenizer tokens = null;
}
